<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 原型链继承------数据之间的干扰、无法向父传参
    // function Person(name, age) {
    //   this.name = name
    //   this.age = age
    // }

    // Person.prototype.eat = function () {
    //   console.log("i can eat")
    // }

    // Person.prototype.say = function () {
    //   console.log('i can say')
    // }

    // function Man() {
    // }

    // Man.prototype = new Person()

    // 组合式继承（伪经典）---缺点：执行父2次
    // function Person(name, age) {
    //   this.name = name
    //   this.age = age
    // }

    // Person.prototype.eat = function () {
    //   console.log("i can eat")
    // }

    // Person.prototype.say = function () {
    //   console.log('i can say')
    // }

    // function Man(name, age) {
    //   Person.call(this, name, age)
    // }

    // Man.prototype = new Person()
    // Man.prototype.constructor = Man

    // Man.prototype.run = function () {
    //   console.log('i can run')
    // }

    // const person1 = new Man('jerry', 20)
    // console.log(person1)

    // 寄生式继承-经典继承
    function Person(name, age) {
      this.name = name
      this.age = age
    }

    Person.prototype.eat = function () {
      console.log("i can eat")
    }

    Person.prototype.say = function () {
      console.log('i can say')
    }

    function Man(name, age) {
      Person.call(this, name, age)
    }

    Man.prototype = Object.create(Person.prototype)
    Man.prototype.constructor = Man

    Man.prototype.run = function () {
      console.log('i can run')
    }

    const person1 = new Man('jerry', 20)
    person1.say()
    console.log(person1)


  </script>

</body>

</html>